package Review.ArrayList;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class playCards {
    private  final String[] suit = {"♣","♥","♦","♠"};
    private List<playingCard> Card = new ArrayList<>();
    //获取花色
    public String get(int data){
        return suit[data];
    }
    private void buyCard(){
        for (int i = 0; i <=13; i++) {
            for (int j=0;j<4;j++){
                String  tmp =  get(j);//获取j位置的花色
                playingCard playingCard = new playingCard(tmp,i);//花色和点数
                this.Card.add(playingCard);//增加到牌中
            }
        }
        Card.add(new playingCard("大王",0));//最后放入大小王
        Card.add(new playingCard("小王",0));
    }
    private  void swap(List<playingCard> Card,int i,int j){
       playingCard playingCard = Card.get(i);
       Card.set(i,Card.get(j));
        Card.set(i,playingCard);
    }
    public  void shuffleCard(){
        Random random = new Random();
        int countCard = this.Card.size();//当前扑克牌的数量
        //从后往前产生随机数打乱牌
        for (int i = countCard-1; i >0 ; i--) {
            int tmpCard = random.nextInt(i);
            //交换
            swap(this.Card,i,tmpCard);
        }
    }

}
